package com.sx.shop.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sx.shop.entity.Shop;
import com.sx.shop.entity.Store;
import com.sx.shop.mapper.ShopMapper;
import com.sx.shop.mapper.StoreMapper;
import com.sx.shop.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StoreService {
    @Autowired
    private StoreMapper storeMapper;

    public void doSave(Store store) {                         //增加和更新
        // TODO Auto-generated method stub
        if(store.getId() == null) {//是新增
            storeMapper.insert(store);
        }else {
            storeMapper.update(store);
        }

    }

    public void doDel(Integer id) {                         //删除
        // TODO Auto-generated method stub
        storeMapper.delete(id);
    }

    public Store selectStoreById(Integer id) {                //查询
        // TODO Auto-generated method stub
        return storeMapper.selectStoreById(id);
    }

    public ResultVo selectStore(String keyword, Integer page , Integer limit,Integer uId) {
        ResultVo vo = new ResultVo();

        PageHelper.startPage( page , limit);//代码下的第一个查询，有分页效果
        List<Store> list = storeMapper.selectStore(keyword,uId);
        PageInfo<Store> pageInfo = new PageInfo<>(list);
        vo.setData(list);
        vo.setCount(pageInfo.getTotal());
        return vo;
    }

    public List<Store> selectStoreByShopid(int shopid) {
        return storeMapper.selectStoreByShopid(shopid);
    }

    public List<Store> selectStoreByCreatebyid(int createby_id) {
        return storeMapper.selectStoreByCreatebyid(createby_id);
    }

    public ResultVo selectStoreByShopid(String keyword , Integer page , Integer limit,int shopid) {
        ResultVo vo = new ResultVo();

        PageHelper.startPage( page , limit);//代码下的第一个查询，有分页效果
        List<Store> list = storeMapper.selectStoreByShopid(shopid);
        PageInfo<Store> pageInfo = new PageInfo<>(list);
        vo.setData(list);
        vo.setCount(pageInfo.getTotal());
        return vo;
    }
}
